Trouble with a connection of two pushbutton and one ldr sensor

Hello guys,

I'm making a project for the university, then I found some problems with coding of Arduino to the circuit with two pushbutton and one LDR sensor. My project is a blind controlled by pushbuttons, LDR sensor, and Alexa. When the sun rises the LDR sensor must detect it and start the opening of the blind. However, the pushbuttons must allow the open or close of the blind.

Can anyone help me? My code permits the pushbuttons works but when the LDR sensor detects the light it doesn't trigger the relay to activate the engine.

Welcome to the forum

Please post your sketch, using code tags when you do

1 Like

Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please post a schematic. Hand drawn, photographed and posted is fine.

1 Like

// C++ code

#define LDR A0
#define Botao1 11
#define Botao2 13
#define Motor1 10
#define Motor2 12

void setup()
{
  pinMode(LDR, INPUT);
  pinMode(Botao1, INPUT);
  pinMode(Botao2, INPUT);
  pinMode(Motor1, OUTPUT);
  pinMode(Motor2, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  int valorLDR = analogRead(LDR);
  
  Serial.println(valorLDR);
  Serial.println(digitalRead(Botao1));
  Serial.println(digitalRead(Botao2));
  
  if (valorLDR < 500) {
    digitalWrite(Motor2, HIGH);
    delay(4000); // Wait for 4000 millisecond(s)
    digitalWrite(Motor2, LOW);
  } else {
    digitalWrite(Motor2, LOW);
  }
  if (digitalRead(Botao2) != 0) {
    digitalWrite(Motor2, HIGH);
  } else {
    digitalWrite(Motor2, LOW);
  }
  
  if (digitalRead(Botao1) != 0) {
    digitalWrite(Motor1, HIGH);
  } else {
    digitalWrite(Motor1, LOW);
  }

I'm newbie here, did it do right?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.