Skip to content

Instantly share code, notes, and snippets.

@buildcircuit
Created June 30, 2020 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buildcircuit/680c386f2c3f7f305574eebe7b579d9e to your computer and use it in GitHub Desktop.
Save buildcircuit/680c386f2c3f7f305574eebe7b579d9e to your computer and use it in GitHub Desktop.
CD4029 up and down counter module responding to sensor
int sensorPin = A0; // select the input pin for the photoresistor
int CLK = 13; // Pin 13 of Arduino gives pulse to CD4029 module
int sensorValue = 0; // variable to store the value coming from the sensor
int RESET=11; // connect to reset pin of CD4029
int UD=12; // connect to UD pin of CD4029
void setup() {
Serial.begin(9600);
pinMode(CLK, OUTPUT);
pinMode(RESET, OUTPUT);
pinMode(UD, OUTPUT);
// reset the counter
digitalWrite(RESET,HIGH);
delay(100);
digitalWrite(RESET,LOW);
// set the counter to count UP
digitalWrite(UD,HIGH);
}
void loop() {
sensorValue = analogRead(sensorPin);
delay(1000);// read the sensor every 1 second.
Serial.println(sensorValue);// print the sensor value
if (sensorValue>1000) // if the sensor value is greater than 1000,increase the count by one
{
digitalWrite(CLK, HIGH);
delay(2000); // wait for 2 seconds
digitalWrite(CLK, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment