digital read and analog write

Hai ,
I am new to Arduino world....
I need a small help that is i want write a code for digital input and analog output using digital read and analog write...
I am doing a small project for that i need to get input from pir sensor and give output to dcmotor in analog values..can anyone help me...please
Arduino mega2560

My. Code is
Int inputpin=2;
Int pirstate=LOW;

Void loop(



Is it correct

Is it correct

What happens when you run the program?

What PIR detector are you using? Post a link to its datasheet.
What DC motor are you using? Link, please
What motor driver are you using? Link. please


C++ is case-sensitive, as you have no doubt by now found out.

Did you look at the basic examples? Because there are some very basic errors here.

int inputpin = 2;
int pirstate = LOW; //You are not using this

void setup() {
  pinMode(2, INPUT);
void loop() {
  if (digitalRead(inputpin) == HIGH)
    analogWrite(8, 0);
    analogWrite(9, 255);

  else {
    analogWrite(8, 255);
    analogWrite(9, 0);

== is the equality comparison operator, = is the assignment operator, be careful not to confuse them

Note that if you have compiler warnings turned on in your preferences and read the warnings a lot
of issues like this will be spotted automatically (although many compiler messages are rather hard
to understand at first)