1

A few days ago I tested a circuit on a breadboard based on a ATmega8a with 1 MHz internal oscilator. It sould turn on and off a relay based on a IR code that is received and if it matches the programmed in the EEPROM it shoud enable or disable the relay. Now I developed a PCB and soldered everything together but now it isn't working. On an Arduino Nano it is working ok.

#include <IRremote.h>
#include <EEPROM.h>

int RECV_PIN = 11;
int RELAY_PIN = 4;
int setpin = 3;
unsigned long work_at;
unsigned long adres;
unsigned long irbuffer;
IRrecv irrecv(RECV_PIN);
decode_results results;

void dump(decode_results *results) {

    if(digitalRead(setpin) == 0){
      work_at = results->value; 
      Serial.println(work_at, HEX);    
    }
    irbuffer = results->value;

}

void eeprom_writer(){
  if (irrecv.decode(&results)) {
    if(digitalRead(setpin) == 0 && work_at != 0){
      EEPROM.put(0, work_at); //put walue
      Serial.println(work_at, HEX);
      adres = work_at;
      Serial.println(adres, HEX);
      delay(1000); //wait
   }
  }
}
void setup()
{
  EEPROM.get(0, adres);
  pinMode(setpin, INPUT_PULLUP);
  pinMode(RELAY_PIN, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

int on = 0;
unsigned long last = millis();

void loop() {
  if (irrecv.decode(&results)) {
    // If it's been at least 1/4 second since the last
    // IR received, toggle the relay
  //  if(&results == adres){
      dump(&results);
      if (millis() - last > 250) {
        on = !on;
        if(on == true && adres == irbuffer){
          delay(5000);
          digitalWrite(RELAY_PIN, on ? HIGH : LOW);
          dump(&results); 
        }else if(on != true  && adres == irbuffer){
          digitalWrite(RELAY_PIN, on ? HIGH : LOW);        
          dump(&results); 
          delay(5000);
        }
      }
    //}
//    Serial.println(dump(&results));
//    Serial.println(count, DEC);

    eeprom_writer();
    last = millis();      
    irrecv.resume(); // Receive the next value
  }
}
  • 1
    Did you solder the ATMega on the PCB? How do you connect everything? – user31481 Oct 31 '17 at 12:14
  • @LookAlterno I soldered it ti the pcb and used dip connectors to conect the iscp uart relay and the ir module. – Coder_fox Oct 31 '17 at 12:36
  • Maybe I should use a pin that supports PWM – Coder_fox Oct 31 '17 at 12:37
0

Changing the internal oscillator to 8MHz helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.