Site icon Making Studio

Useless Machine Take Two!

This was my useless(ish) machine:

It wasn’t actually useless.

I had some issues with the hot glue, which seems to have disconnected my soldering.

So it was actually powered by this push button.

But now!

It works!

This is my code:
 

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 
int photoval = 0;
int photo = 0;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);       // open the serial port at 9600 bps: 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  myservo.write(90); // set servo to mid-point

}

void loop() {
  
  photoval = analogRead(photo);
  Serial.print("photoval after reading = ");
  Serial.println(photoval);
  photoval = map(photoval, 0, 900, 0, 255);
  Serial.print("photoval after mapping = ");
  Serial.println(photoval);
    if (photoval < 240)
    {
  myservo.write(20);                  // rotate counterclockwise full speed
  delay(910); 
  myservo.write(88);                  // stop
  delay(2000);
    }
  // put your main code here, to run repeatedly:

}

Exit mobile version