Hello, sorry for my English in my uploaded photo which is in black circle i every time my sequence start first is pin 8 and 9 will turn on after 2sec it will turn off and pin 10 and 11 will turn on to read the analog value converted to concentration but it read the value only ones, my goal is to read the value if pin 10 and 11 is on and it will stop when pin 10 and 11 is off.
i hope somebody can help me, Thank you.
Don't past images of code.
In the Arduino IDE click on Edit then Copy for Forum, then come back here and do a paste.
You will see a big differenct on how the code appears.
Which is your arduino?
Post your complete code.
Which pin is anlogPin?
const int buttonPin = 3; // Button pin
const int ledPin8 = 8; // Loading Motor +
const int ledPin9 = 9; // Loading Motor -
const int ledPin10 = 10; // Lamp +
const int ledPin11 = 11; // Lamp -
int buttonState = 0; // Variable to store the button state
int lastButtonState = 0; // Previous button state to detect changes
bool sequenceStarted = false; // To check if the sequence has started
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 13
LiquidCrystal_I2C lcd(0x27,3,2);
int analogPin = A1;
int val = 0;
void setup() {
// Initialize the button pin as input and LED pins as outputs
pinMode(buttonPin, INPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
digitalWrite(ledPin10, LOW);
digitalWrite(ledPin11, LOW);
lcd.begin(16,4);
lcd.backlight();
Serial.begin(9600);
lcd.setCursor(2,2);
lcd.print("LUBRICANT TESTING");
}
void loop() {
buttonState = digitalRead(buttonPin); // Read the button state
Serial.println(buttonState);
// Check if the button was pressed (change from LOW to HIGH)
if (buttonState == HIGH && lastButtonState == LOW && !sequenceStarted) {
// Button has been pressed, start the sequence
sequenceStarted = false;
startSequence();
}
// Update the last button state
lastButtonState = buttonState;
}
void startSequence() {
// Turn on LED 1
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin9, HIGH);
lcd.clear();
lcd.setCursor(3,2);
lcd.print("LUBRICANT LOAD");
delay(2000); // Wait for 2 seconds
// Turn off LED 1
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
lcd.clear();
// Turn on LED 2
digitalWrite(ledPin10, HIGH);
digitalWrite(ledPin11, HIGH);
float sensorValue= analogRead (analogPin);
float Concentration = (sensorValue);
lcd.setCursor(1,2);
lcd.print(Concentration);
lcd.setCursor(6,2);
lcd.print("%");
lcd.setCursor(1,1);
lcd.print(sensorValue);
delay(2000); // Wait for 2 seconds
// Turn off LED 2
digitalWrite(ledPin10, LOW);
digitalWrite(ledPin11, LOW);
lcd.clear();
lcd.setCursor(2,3);
lcd.print("END OF TESTING");
delay(2000); // Wait for 2 seconds
lcd.clear();
lcd.setCursor(7,4);
lcd.print("READY ");
lcd.setCursor(4,2);
lcd.print("FOR TESTING");
// End the sequence, no further action is taken until the next button press
sequenceStarted = false;
}
Thank you sir for the reply
I simulated your code here:
but I didn't understand what doesn't work.
See post #2
Your code is unreadable and may contain errors if not posted correctly.
Hi Sir,
My goal is i first if i push the button to start the sequence, i used arduino uno and relay module to activate the motor pump,halogen lamp and LDR to read the light came from halogen lamp.
My sequence, if i push the button it will activate the relay to run the pump after 10sec, it will turn off and another relay will on to activate the halogen lamp it will stay on up to 3 min so that the LDR can read the light from the halogen after 3 min i will reset the sequence.
i hope can any body can help me.
Thank you.
Yes please read post #2
const int buttonPin = 3; // Button pin
const int ledPin8 = 8; // Loading Motor +
const int ledPin9 = 9; // Loading Motor -
const int ledPin10 = 10; // Lamp +
const int ledPin11 = 11; // Lamp -
int buttonState = 0; // Variable to store the button state
int lastButtonState = 0; // Previous button state to detect changes
bool sequenceStarted = false; // To check if the sequence has started
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 13
LiquidCrystal_I2C lcd(0x27, 3, 2);
int analogPin = A1;
int val = 0;
void setup() {
// Initialize the button pin as input and LED pins as outputs
pinMode(buttonPin, INPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin9, HIGH);
digitalWrite(ledPin10, HIGH);
digitalWrite(ledPin11, HIGH);
lcd.begin(16, 4);
lcd.backlight();
Serial.begin(9600);
lcd.setCursor(2, 2);
lcd.print("LUBRICANT TESTING");
}
void loop() {
buttonState = digitalRead(buttonPin); // Read the button state
// Check if the button was pressed (change from LOW to HIGH)
if (buttonState == HIGH && lastButtonState == LOW && !sequenceStarted) {
// Button has been pressed, start the sequence
sequenceStarted = HIGH;
startSequence();
}
// Update the last button state
lastButtonState = buttonState;
}
void startSequence() {
// Turn on LED 1
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
lcd.clear();
lcd.setCursor(3, 2);
lcd.print("LUBRICANT LOAD");
delay(2000); // Wait for 2 seconds
// Turn off LED 1
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin9, HIGH);
lcd.clear();
// Turn on LED 2
digitalWrite(ledPin10, LOW);
digitalWrite(ledPin11, LOW);
float sensorValue = analogRead(analogPin);
float Concentration = (sensorValue);
lcd.setCursor(1, 2);
lcd.print(Concentration);
lcd.setCursor(6, 2);
lcd.print("%");
lcd.setCursor(1, 1);
lcd.print(sensorValue);
delay(20000); // Wait for 2 seconds
// Turn off LED 2
digitalWrite(ledPin10, HIGH);
digitalWrite(ledPin11, HIGH);
lcd.clear();
lcd.setCursor(2, 3);
lcd.print("END OF TESTING");
delay(2000); // Wait for 2 seconds
lcd.clear();
lcd.setCursor(7, 4);
lcd.print("READY ");
lcd.setCursor(4, 2);
lcd.print("FOR TESTING");
// End the sequence, no further action is taken until the next button press
sequenceStarted = false;
}
Hi sir her is the code and it is working to me my problem is i want to read the value continues during the LED 2 is ON and Stop reading after 20000 ms or LED is off
Hello mrayio800
Take some time and study the design and coding of a finite state machine, FSM, for your project.
const int buttonPin = 3; // Button pin
const int ledPin8 = 8; // Loading Motor +
const int ledPin9 = 9; // Loading Motor -
const int ledPin10 = 10; // Lamp +
const int ledPin11 = 11; // Lamp -
int buttonState = 0; // Variable to store the button state
int lastButtonState = 0; // Previous button state to detect changes
bool sequenceStarted = false; // To check if the sequence has started
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 13
LiquidCrystal_I2C lcd(0x27, 3, 2);
int analogPin = A1;
int val = 0;
void setup() {
// Initialize the button pin as input and LED pins as outputs
pinMode(buttonPin, INPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin9, HIGH);
digitalWrite(ledPin10, HIGH);
digitalWrite(ledPin11, HIGH);
lcd.begin(16, 4);
lcd.backlight();
Serial.begin(9600);
lcd.setCursor(2, 2);
lcd.print("LUBRICANT TESTING");
}
void loop() {
buttonState = digitalRead(buttonPin); // Read the button state
// Check if the button was pressed (change from LOW to HIGH)
if (buttonState == HIGH && lastButtonState == LOW && !sequenceStarted) {
// Button has been pressed, start the sequence
sequenceStarted = HIGH;
startSequence();
startSequence1();
}
// Update the last button state
lastButtonState = buttonState;
}
void startSequence1() {
}
void startSequence() {
// Turn on LED 1
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
lcd.clear();
lcd.setCursor(3, 2);
lcd.print("LUBRICANT LOAD");
delay(2000); // Wait for 2 seconds
// Turn off LED 1
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin9, HIGH);
lcd.clear();
// Turn on LED 2
digitalWrite(ledPin10, LOW);
digitalWrite(ledPin11, LOW);
delay(20000);
float sensorValue = analogRead(analogPin);
float Concentration = ((900-sensorValue)/9);
lcd.setCursor(1, 2);
lcd.print(Concentration);
lcd.setCursor(6, 2);
lcd.print("%");
lcd.setCursor(1, 1);
lcd.print(sensorValue);
delay(20000); // Wait for 2 seconds
// Turn off LED 2
digitalWrite(ledPin10, HIGH);
digitalWrite(ledPin11, HIGH);
lcd.clear();
lcd.setCursor(2, 3);
lcd.print("END OF TESTING");
delay(2000); // Wait for 2 seconds
lcd.clear();
lcd.setCursor(7, 4);
lcd.print("READY ");
lcd.setCursor(4, 2);
lcd.print("FOR TESTING");
// End the sequence, no further action is taken until the next button press
sequenceStarted = false;
}
You set pin 10 and 11 to OUTPUT.
What relay?
What pump?
What relay?
What lamp?
What LDR?
This is 20 seconds.
Should this be like this (20 x 4):
LiquidCrystal_I2C lcd(0x27,20,4);
I do not know how this works... but usually these screens are 16x2 or 20x4... and usually lcd.init() is used (versus lcd.begin())
Nothing happens here:
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

