Lucky Fortune Teller With Arduino Humidity/temperature Reader
by lfishe01 in Circuits > Arduino
114 Views, 0 Favorites, 0 Comments
Lucky Fortune Teller With Arduino Humidity/temperature Reader
This is a friendly little fortune teller! Using an Arduino humidity/temperature sensor reader, this project gives out lucky phrases when you hold the fortune cookie in your palm.
Supplies
What you'll need:
Arduino Uno and accompanying wires
Computer to code with and connect to
3D printer and filament
Wood (or another sturdy, structural material)
Decorative beads (optional)
3D Print a Fortune Cookie
There are many free fortune cookie prints available on Thingiverse and other websites! Here's the link to the one I used by user DaveMakesStuff: https://www.thingiverse.com/thing:5428712
I printed mine a little larger than the thingiverse file offered, so as to make sure it could fit the humidity/temperature sensor reader. My fortune cookie is about 2.7 inches in width. Obviously the print could've been a little better, and I think with more practice with the 3D printer, it would've been. If you're relatively new to 3D printing like me, definitely give yourself time to go through a few trials of it!
Build the Housing
Using scrap wood, I fashioned this structure to hold my board in the back inconspicuously. You can make yours with any sturdy, structural material you might have around. Optionally, you can decorate your structure with paint, unique cuts, or beads (like I did).
Arduino Humidity/Temperature Sensor Reader Setup
Get the Arduino sensor working by wiring it according to this photo and uploading this code the board. The green wire goes into pin 2, the red wire goes into 5V, and the black wire goes into GND.
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 7 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT11 (AM2302)
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
String fortunes[5] = {
"You will have a great day!",
"Good things come to those who wait.",
"A smile is your passport into the hearts of others.",
"You are a person of culture and charm.",
"The best way to predict the future is to create it."
};
float prevTemp = 0;
float prevHumidity = 0;
void setup() {
Serial.begin(9600);
dht.begin();
Serial.println(F("DHTxx Unified Sensor Example"));
sensor_t sensor;
dht.temperature().getSensor(&sensor);
delayMS = sensor.min_delay / 1000; // Set delay between sensor readings based on sensor details
}
void loop() {
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
if (abs(event.temperature - prevTemp) >= 0.2) {
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
int index = random(5); // Generate a random index for the fortunes array
Serial.println("Fortune Cookie Phrase: " + fortunes[index]);
prevTemp = event.temperature;
}
}
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
if (abs(event.relative_humidity - prevHumidity) >= 1.0) {
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
int index = random(5); // Generate a random index for the fortunes array
Serial.println("Fortune Cookie Phrase: " + fortunes[index]);
prevHumidity = event.relative_humidity;
}
}
delay(delayMS); // Add a delay based on sensor details
}
Downloads
Put Everything Together!
Put the humidity/temperature sensor reader into the cookie and the board in the wood housing structure, and connect everything to the code on your computer. Click open the Serial Monitor on your computer, and test the fortune teller by warming up the cookie in your hands –– voila! you should be receiving plenty of fortuitous phrases.