Anti-Snooze Machine
Is it really difficult to wake up from your alarm, does your snooze button seem to always be in reach? Well have no fear this anti-snooze machine has you covered.
Place the touch-sensor on the snooze button, so next time you decide to reach in for the appealing snooze button, the surfer will zoom far from your touch, until you unplug the agent itself.
This project is by Alex Reiner, Edgar Schefer and Arindam Katoch
Supplies
Parts List
- 2 x 9V Battery
- Resistors:
- 2 x 220 Ω ± 5%
- 1 MΩ ± 5%
- 2 x photoresistor
- 2 x DC Motor
- L293D
- Arduino Uno
- Bread Board
- 2 x Bearings (d = 22 mm)
- 3 plastic wheels (d = 28 mm)
- Phone
Assembly
The images will help guide you with the assembly of the electrical component, as shown in the Fritzing diagram.
Additionally, we have provided you with an explosion diagram of the machines body. (it is to be assembled from bottom to top)
Downloads
Programming the Arduino
//Libraries
#include <CapacitiveSensor.h>//https://github.com/PaulStoffregen/CapacitiveSensor
//Parameters
bool autocal = 0;
const int numReadings = 10;
long readings [numReadings];
int readIndex = 0;
long total = 0;
const int sensitivity = 1000;
const int thresh = 200;
const int csStep = 10000;
CapacitiveSensor cs = CapacitiveSensor(2, 3);
//Motor1
const int MotorPin1 = 5;
const int MotorPin2 = 6;
//Motor2
const int MotorPin3 = 10;
const int MotorPin4 = 9;
void setup() {
//Init Serial USB
Serial.begin(9600);
Serial.println(F("Initialize System"));
;
//Init cs
if (autocal == 0) {
{
cs.set_CS_AutocaL_Millis(0xFFFFFFFF);
}
}
}
void loop() {
//Photoresistors
int PRes1 = analogRead(A0);
int PRes2 = analogRead(A1);
Serial.println("Analog PRes1 : ");
Serial.println(PRes1);
Serial.println("Analog PRes2 : ");
Serial.println(PRes2);
// Touchpad
Serial.println("touch : ");
Serial.println(smooth());
long touch = smooth();
delay(200);
// DCMotors
pinMode(MotorPin1, OUTPUT);
pinMode(MotorPin2, OUTPUT);
pinMode(MotorPin3, OUTPUT);
pinMode(MotorPin4, OUTPUT);
digitalWrite(MotorPin1, LOW);
digitalWrite(MotorPin2, LOW);
digitalWrite(MotorPin3, LOW);
digitalWrite(MotorPin4, LOW);
long PRes1_threshold = 800 // Calibrate values to match what the photoresistor needs
long Pres2_threshold = 800;
if (touch > 300)
{
if (PRes1>PRes1_threshold)
{
while (PRes2<Pres2_threshold)
{
{
digitalWrite(MotorPin1, HIGH);
digitalWrite(MotorPin2, LOW);
digitalWrite(MotorPin3, HIGH);
digitalWrite(MotorPin4, LOW);
int PRes2 = analogRead(A1);
Serial.println(PRes2);
if (PRes2>Pres2_threshold)
{
break;
}
}
}
}
else if (PRes2>Pres2_threshold)
{
while (PRes1<PRes1_threshold)
{
{
digitalWrite(MotorPin1, LOW);
digitalWrite(MotorPin2, HIGH);
digitalWrite(MotorPin3, LOW);
digitalWrite(MotorPin4, HIGH);
int PRes1 = analogRead(A0);
Serial.println(PRes1);
if (PRes1>PRes1_threshold)
{
break;
}
}
}
}
else
{
while (PRes1<PRes1_threshold or PRes2<Pres2_threshold)
{
digitalWrite(MotorPin1, HIGH);
digitalWrite(MotorPin2, LOW);
digitalWrite(MotorPin3, HIGH);
digitalWrite(MotorPin4, LOW);
int PRes1 = analogRead(A0);
Serial.println(PRes1);
int PRes2 = analogRead(A1);
Serial.println(PRes2);
long touch = smooth();
if (PRes1>PRes1_threshold or PRes2>Pres2_threshold )
{
break;
}
}
}
long touch = smooth();
}
}
long smooth() { /* function smooth */
////Perform average on sensor readings
long average;
// subtract the last reading:
total = total - readings[readIndex];
// read the sensor:
readings[readIndex] = cs.capacitiveSensor(sensitivity);
// add value to total:
total = total + readings[readIndex];
// handle index
readIndex = readIndex + 1;
if (readIndex >= numReadings) {
readIndex = 0;
}
// calculate the average:
average = total / numReadings;
return average;
}
Showcase
References
- https://create.arduino.cc/projecthub/MisterBotBreak/how-to-use-a-photoresistor-46c5eb
- https://lastminuteengineers.com/l293d-dc-motor-arduino-tutorial/
- https://www.aranacorp.com/en/create-a-capacitive-sensor-with-arduino/
- https://www.mrelectrouino.com/2019/07/diy-control-2-dc-motor-using-l293d.html
- https://forum.arduino.cc/t/a-general-question-regarding-a-simple-dc-motor-combined-with-an-h-bridge-l293d/631289