*urgent have a couple days to get assignment done* looking to make a aurduino r4 uno minima photoresistor activating servoarm

im looking for someone to be able to explain how to build it with the items and code i have, i came across this from other forums but no build diagram. please find below the items im using and the sketch code ill be using. any advice or instructions would be greatly appreciated.

  • Arduino Uno or Arduino compatible board
  • Photoresistor
  • ~5k-10k ohm resistor
  • SG90 servo motor with an arm
  • LCD1602 module
  • 10k ohm potentiometer
  • Breadboard
  • Jumper wires

Sketch code is as follows:

#include <Arduino.h>
#include <Wire.h>
#include <Servo.h>
#include <LiquidCrystal.h>

#define rs 2
#define e 3
#define d4 4
#define d5 5
#define d6 6
#define d7 7
#define photoPin A0
#define servoPin 9

LiquidCrystal lcd(rs, e, d4, d5, d6, d7);
Servo servo;

int val = 0;
int dodged = 0;

// this value is dependent on the photoresistor and the brightness of your TV
// you will probably need to test different values here
int threshold = 350;

// this sets the starting servo position and the distance traveled for a button press
// you may need to change these values depending on the servo motor you are using
int startDegs = 180;
int pressDegs = 15;

void updateLCD()
{
  lcd.begin(16, 2);
  lcd.clear();
  lcd.home();
  lcd.print("Dodged: ");
  lcd.print(dodged);
}

void setup()
{
  Serial.begin(9600);
  Wire.begin();

  pinMode(photoPin, INPUT);
  servo.attach(servoPin);
  servo.write(startDegs);
  updateLCD();
}

void loop()
{
  val = analogRead(photoPin);

  // uncomment this line for calibration
  // Serial.println(val); 

  if (val > threshold)
  {
    delay(50);
    servo.write(startDegs - pressDegs);
    delay(200);
    servo.write(startDegs);
    dodged++;
    updateLCD();
    delay(1000); // "debouncing"
  }
}

Please edit your post, select all code and click the <CODE/> button; next save your sketch.

This will apply code tags to your code which makes it easier to read and copy and the forum software will display it properly.

You might want to look at this How to get the best out of this forum before you proceed any further.

It tells you how to post code correctly here.

That is way too long, and also unnecessary, plus it means that you will miss many lightning strikes.

Are you detecting visible lightning strikes with a photo diode? That is not the right way to do this. You should use an electromagnetic sensor like an antenna, or a FM radio tuned to a station with no reception. There are many proper detector circuits on line.

What does the servo do and why?

Why is this request urgent?

im using a photoresistor to detect changes in light from a monitor and when it does it makes the servoarm push a button,

So it is not real lightning then?

no it is not real lightning

So the name in the thread's title should not be "dodger" - a person who not doing what they should do but "simulator" - a way of artificially creating the effect of something else.

Use the big black pencil next to the first thread and edit your title.

Also explain why this request is urgent?
Is it because you started your school assignment too late? What is your deadline?

there updated, now will you assist me? im finding software side of things simple but hardware seems to be a bit annoying as no matter how much i read and reread, its just not sinking in sadly

Their are different types of LCD1602 module. Some have an I2C interface, some have a SPI interface and others have a multi pin interface. Some require a 3V3 power and others a 5V supply. You need to know exactly what you have.

This is an official Arduino document sanitised so as not to offend people who are offended by the the thought of slavery in one small period of time. On driving one type of display.
LCD display

But you really need to specify what type you have, or the link to where you bought it from.

So again what sort. Is it a light dependent resistor?
If so then this is the circuit:-

What is this for?

I entered your specifications in a general search and found one very close match: arduino photoresistor servo lcd

And another lesser match, but with some explanations..

The problem with that second link is that the photo resistor is in the lower leg of the potential divider. This gives a reducing reading the brighter the light is. You can simply compensate for this in code but it is a bit counterintuitive.

Code requires is:-

lightValue = 1023 - digitalRead(analogPin);