Mohamed Jinas
Published © MIT

How its made: Talking Cactus

Cactus that tweets when it needs water

BeginnerShowcase (no instructions)2 hours4,954
How its made: Talking Cactus

Things used in this project

Story

Read more

Code

Code snippet #1

Plain text
//Analog pin thats connected to the sensor
int sensorPin = A0;
//Variable to store the sensor reading
int sensorValue;

void setup() {
    Serial.begin(9600);
    pinMode(13, OUTPUT);
}

void loop() {

    //Read and store the value of sensor data
    sensorValue = analogRead(sensorPin);
    //Output the value to the serial
    Serial.println(sensorValue);

    //Wait for 1 second before reading again
    delay(1000);
}

Code snippet #2

Plain text
//Analog pin thats connected to the sensor
int sensorPin = A0;
//Variable to store the sensor reading
int sensorValue;

void setup() {
    Serial.begin(9600);
    pinMode(13, OUTPUT);
}

void loop() {

    //Read and store the value of sensor data
    sensorValue = analogRead(sensorPin);
    //Output the value to the serial
    Serial.println(sensorValue);

    //Wait for 1 second before reading again
    delay(1000);
}

Code snippet #3

Plain text
# importing the module 
import tweepy
import time
import serial
  
# personal details 
consumer_key =""
consumer_secret =""
access_token =""
access_token_secret =""

serial_port = 'COM4' #Define serial port
baud_rate = 9600 #In arduino, Serial.begin(baud_rate)
  
# authentication of consumer key and secret 
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 
  
# authentication of access token and secret 
auth.set_access_token(access_token, access_token_secret) 
api = tweepy.API(auth) 
  
# update the status 


ser = serial.Serial(serial_port, baud_rate)
while True:
    line = ser.readline()
    line = line.decode("utf-8")

    value = float(line)
    
    if (value < 300):

        api.update_status(status ="HEY!! I NEED WATER.. My thirsty level is {}".format(value))
    else:
        print("i am alright.. My thirsty level is {}".format(value))
    time.sleep(600)     

    

Code snippet #4

Plain text
# importing the module 
import tweepy
import time
import serial
  
# personal details 
consumer_key =""
consumer_secret =""
access_token =""
access_token_secret =""

serial_port = 'COM4' #Define serial port
baud_rate = 9600 #In arduino, Serial.begin(baud_rate)
  
# authentication of consumer key and secret 
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 
  
# authentication of access token and secret 
auth.set_access_token(access_token, access_token_secret) 
api = tweepy.API(auth) 
  
# update the status 


ser = serial.Serial(serial_port, baud_rate)
while True:
    line = ser.readline()
    line = line.decode("utf-8")

    value = float(line)
    
    if (value < 300):

        api.update_status(status ="HEY!! I NEED WATER.. My thirsty level is {}".format(value))
    else:
        print("i am alright.. My thirsty level is {}".format(value))
    time.sleep(600)     

    

Credits

Mohamed Jinas

Mohamed Jinas

3 projects • 3 followers
Student, a Software developer based in Maldives.

Comments